﻿using System;
using System.Windows.Forms;
using FlyData.CoreCode.Email;
using FlyData.Properties;
using Microsoft.Office.Interop.Excel;

namespace FlyData
{
    public partial class SendEmailDialog : Form
    {
        
        public SendEmailDialog()
        {
            InitializeComponent();
            
        }


        private void SendEmailButtonClick(object sender, EventArgs e)
        {
            Range excelSelection = Globals.ThisWorkbook.Application.Selection;
//            Globals.ThisWorkbook.Application.Selection
//            var activeWorksheet = ((Microsoft.Office.Interop.Excel.Worksheet)Application.ActiveSheet);
//            Excel.Range firstRow = activeWorksheet.get_Range("A1", missing);
//            firstRow.EntireRow.Insert(Excel.XlInsertShiftDirection.xlShiftDown, System.Type.Missing);
//            Excel.Range newFirstRow = activeWorksheet.get_Range("A1", missing);
//            newFirstRow.Value2 = "This text was added by u0000000sing code";



            String senderEmail = senderEmailIdTextbox.Text +"@gmail.com";
            String password = snederEmailPasswordTextbox.Text;
            String recipiantEmail = recipientEmailIndicatorTextbox.Text;
            String subject = emailSubjectTestbox.Text;
            String messageHeader = messaggeHeaderTestbox.Text;
            String messageFooter = messaggeFooterTextbox.Text;


            bool isMailSentToContactsFromForm = Convert.ToBoolean(RecipiantOptionsComboBox.SelectedIndex);
            new Email().Send(senderEmail, password, recipiantEmail, subject, messageHeader,messageFooter,  excelSelection, isMailSentToContactsFromForm);
            this.Dispose();
        }

        private void SendEmailDialogLoad(object sender, EventArgs e)
        {
            RecipiantOptionsComboBox.SelectedIndex = 0;
        }

        private void RecipiantOptionsComboBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            if (RecipiantOptionsComboBox.SelectedIndex == 0)
            {
                recipiantEmailIndicatorLabel.Text = Resources.SendEmailDialog_RecipiantOptionsComboBox_Column_Label_Name;
            }
            else
            {
                recipiantEmailIndicatorLabel.Text = Resources.SendEmailDialog_RecipiantOptionsComboBox_E_Mail_Label_Name;
            }
        }


    }
}
